/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sUtils;

import javax.microedition.media.*;
import java.io.*;
import javax.microedition.io.Connector;
import javax.microedition.io.file.*;


public class Sounds {

    static public Player load( String file, String res, String mime )
    {
        Player player = null;
        InputStream is = null;
        if (file!=null)
        {
            try {
                FileConnection f = (FileConnection) Connector.open(file,Connector.READ);
                is = f.openInputStream();
                f.close();
            } catch (Exception e) { is = null; }
        }
        
        try 
        {
            if (is==null && res!=null) is = res.getClass().getResourceAsStream(res);
            if (is!=null)
            {
                player = Manager.createPlayer(is, mime);
                player.setLoopCount(1);
                player.prefetch();
                player.realize();
            }
        }
        catch(Exception e)
        {
            player=null;
        }
        if (is!=null) try { is.close(); } catch (Exception e) {}

        return player;
    }

}
